import { FMVCS } from "../../fgui/fmvc/FMVCS";
import GuideVO from "./GuideVO";
import { ConstDefine } from "../common/ConstDefine";
import Manager from "../../manager/Manager";

export default class GuideData extends FMVCS.FData {
    protected _vo: GuideVO = new GuideVO();
    get vo () {
        return this._vo;
    }
    config: {[key: string]: ConstDefine.Config.GuideConfig} = null;

    curStep: ConstDefine.Guide.EventItemData = null;

    constructor(){
        super();
        Manager.res.getConfigByName(`guideconfig`).then((config: {[key: string]: ConstDefine.Config.GuideConfig}) => {
            this.config = config
        });
    }

    setGuide(info: ConstDefine.Guide.EventItemData){
        let isGuide = false;
        let guideID = info.id;
        let step = info.step;
        let obj = info.obj;
        if(this.config && this.config[guideID] && info && obj){
            let guide = this.config[guideID].guide[step];
            this.curStep = info;
            if(guide){
                let rect = obj.localToGlobalRect(0, 0, obj.width, obj.height);
                this.vo.guideID = guideID;
                this.vo.step = step;
                this.vo.x = rect.x - (obj.pivotX * obj.width);
                this.vo.y = rect.y- (obj.pivotY * obj.height);
                this.vo.w = obj.width;
                this.vo.h = obj.height;
                this.vo.text = guide.text;
                isGuide = true;
            }
        }
        return isGuide;
    }

    getHaveNextStep(){
        let bool = false;
        let curConfig = this.config[this.curStep.id];
        if(curConfig){
            let nextGuide = curConfig.guide[this.curStep.step + 1];
            bool = !!nextGuide;
        }
        return bool;
    }
}